const express =require('express')
//创建 express应用
const app =express()
const cors = require('cors')
//连接数据库
const mongoose =require('mongoose')
mongoose.connect('mongodb://localhost:27017/h52006', {useNewUrlParser: true, useUnifiedTopology: true});
//引入路由中间件
const messageRouter =require('./router/message.js')
const sessionsRouter =require('./router/sessions.js')
//对请求数据做处理
app.use(express.json())
app.use(express.urlencoded({extended:false}))
//使用路由中间件
app.use(cors())
app.use('/api/v1/message',messageRouter)
app.use('/api/v1/sessions',sessionsRouter)
//监听端口
app.listen(9527,()=>{
  console.log('server is runningat 9527')
})